﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//这是Login
namespace 共享单车管理系统
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }


        public static string UserID = "";
        public static string username = "";
        public static string EmployeeID = "";
        public static bool Bflag = false;//f普工t管理员
        public static bool Dflag=false;// f普工t销售员工



        private void btnok_Click(object sender, EventArgs e)
        {
            if(txtName.Text==""||txtPwd.Text=="")
            {
                MessageBox.Show("输入账号和密码");
            }
            else
            {
                DB.GetCn();
                if(radioButton1.Checked)
                {
                    string str = "select * from Users where UserID='"
                        + txtName.Text + "'and Password='" + txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if(dt.Rows.Count>0)
                    {
                        MessageBox.Show("登录成功");
                        UserID = txtName.Text;
                        Form1.Aflag = true;
                       
                        Form1.flag = 1;
                        this.Close();
                        this.DialogResult = DialogResult.OK;

                    }
                    else
                    {
                        MessageBox.Show("账号或密码错误");
                        Form1.Bflag = false;
                    }
                }
                if(radioButton2.Checked)
                {
                    string str = "select * from Employee where EmployeeID='"
                          + txtName.Text + "'and Password='" + txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("登录成功");
                        EmployeeID = txtName.Text;


                        Form1.flag = 2;
                        Form1.Aflag= false;
                        if (dt.Rows[0][7].ToString()== "D1004")
                        {
                            Dflag = true;
                        }
                        else
                        {
                            Dflag= false;
                        }
                        Tinder t1 = new Tinder();
                        t1.ShowDialog();

                    }










                    else
                    {
                        MessageBox.Show("账号或密码错误");
                    }
                }


                if (radioButton3.Checked)
                {
                    string str = "select * from Admin where AdminID='"
                        + txtName.Text + "'and Password='" + txtPwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("登录成功");
                        UserID = txtName.Text;
                        Bflag = true;
                        Form1.flag = 2;
                        Tinder t1 = new Tinder();
                        t1.ShowDialog();
                        //this.Close();
                       // this.DialogResult = DialogResult.OK;

                    }
                    else
                    {
                        MessageBox.Show("账号或密码错误");
                    }
                }


            }
        }

        private void btnCance_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }
    }
}
